Java 7 Recipes: A Problem-Solution Approach by Josh Juneau; Carl Dea; Freddy Guime; John O'Conner
Author:Josh Juneau; Carl Dea; Freddy Guime; John O'Conner
Language: eng
Format: epub
Publisher: Apress®
Published: 2011-12-31T05:00:00+00:00
KeyboardMoveBehavior keyboardMoveBehavior
= new KeyboardMoveBehavior(userMovementGroup, transformGroup);
keyboardMoveBehavior.setSchedulingBounds(new BoundingSphere(new Point3d(), 1000f));
userTransformGroup.addChild(keyboardMoveBehavior);
transformGroup.addChild(userTransformGroup);
/// Class definition
class KeyboardMoveBehavior extends Behavior {
@Override
public void initialize() {
this.wakeupOn(new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED));
currentAxis = 0f;
}
@Override
public void processStimulus(Enumeration criteria) {
while (criteria.hasMoreElements()) {
Object element = criteria.nextElement();
if (element instanceof WakeupOnAWTEvent) {
WakeupOnAWTEvent event = (WakeupOnAWTEvent) element;
for (AWTEvent awtEvent : event.getAWTEvent()) {
if (awtEvent instanceof KeyEvent) {
KeyEvent keyEvent = (KeyEvent) awtEvent;
if (keyEvent.getKeyCode() == KeyEvent.VK_LEFT) {
moveLeft();
} else if (keyEvent.getKeyCode() == KeyEvent.VK_RIGHT) {
moveRight();
} else if (keyEvent.getKeyCode() == KeyEvent.VK_UP) {
moveForward();
} else if (keyEvent.getKeyCode() == KeyEvent.VK_DOWN) {
moveBackwards();
}
}
}
}
}
this.wakeupOn(new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED));
}
}
The KeyboardBehavior extends the Behavior class and implements the initialize() and processStimulus() methods. The initialize() method registers the stimuli that the behavior class will respond to. This recipe calls upon wakeupOn(new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED)) to register an interest in any key that is pressed.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
The Mikado Method by Ola Ellnestam Daniel Brolund(25280)
Hello! Python by Anthony Briggs(24331)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(23419)
Kotlin in Action by Dmitry Jemerov(22501)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(21955)
Dependency Injection in .NET by Mark Seemann(21836)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(20699)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(19514)
Grails in Action by Glen Smith Peter Ledbrook(18592)
Adobe Camera Raw For Digital Photographers Only by Rob Sheppard(17028)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(15836)
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(13683)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(11847)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(11149)
A Developer's Guide to Building Resilient Cloud Applications with Azure by Hamida Rebai Trabelsi(10619)
Hit Refresh by Satya Nadella(9185)
The Kubernetes Operator Framework Book by Michael Dame(8560)
Exploring Deepfakes by Bryan Lyon and Matt Tora(8400)
Robo-Advisor with Python by Aki Ranin(8350)